package com.house.keep.listener;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.house.keep.MqConstant;
import com.house.keep.domain.CanalMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author lkz
 * @className CanalRabbitMQListener
 * @description
 * @date 2024/5/16 10:12
 **/
@Component
@Slf4j
public class CanalRabbitMQListener {


    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(value = MqConstant.CANAL_QUEUE, durable = "true"),
                    exchange = @Exchange(value = MqConstant.CANAL_EXCHANGE),
                    key = MqConstant.CANAL_ROUTING_KEY
            )
    })
    public void handleCanalDataChange(String message) {
        log.info("[canal] 接收消息: {}", JSON.toJSONString(message));
        CanalMessage bean = JSONUtil.toBean(message, CanalMessage.class);
        log.info("bean:{}",bean);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(value = MqConstant.CANAL_QUEUE_2, durable = "true"),
                    exchange = @Exchange(value = MqConstant.CANAL_EXCHANGE),
                    key = MqConstant.CANAL_ROUTING_KEY_2
            )
    })
    public void handleCanalDataChange2(String message) {
        log.info("[canal-handleCanalDataChange2] 接收消息: {}", JSON.toJSONString(message));
        CanalMessage bean = JSONUtil.toBean(message, CanalMessage.class);

    }


}
